var Tool = require("../common/tool.js");

var Map = React.createClass({
    componentDidMount:function(){
        var that = this;
        that.mapObj = new AMap.Map(this.refs.container, {
            center:[120.157696, 30.285087],
            level:11  //地图显示的比例尺级别  
        });
        AMap.plugin(['AMap.ToolBar','AMap.Scale',],
            function(){
                that.mapObj.addControl(new AMap.ToolBar());
                that.mapObj.addControl(new AMap.Scale());
        });
    },
    componentWillReceiveProps: function(nextPro){
        this.initMap(nextPro.markPlace);
    },
    initMap:function(_markedPlaces){
        var that = this;
        
        //对已经添加的地方进行打点标记
        if(_markedPlaces){
            that.oldMarker = new AMap.Marker({
                icon:'images/mark.png',
                map:that.mapObj
            });
            if(_markedPlaces.longitude){
                that.oldMarker.setPosition([_markedPlaces.longitude, _markedPlaces.latitude]);
            }
        }
        
        
    },
    render:function(){
        return (
            <div className="m-editMap">
                <div className="edit-map" ref="container"></div>
            </div>
        )
    }
});
module.exports = Map;